package com.example.yuejian21.nongfusanquan.yuejian21.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;

import com.example.yuejian21.nongfusanquan.yuejian21.R;
import com.example.yuejian21.nongfusanquan.yuejian21.adapter.ClubAdapter;
import com.example.yuejian21.nongfusanquan.yuejian21.adapter.ClubcourseAdapter;
import com.example.yuejian21.nongfusanquan.yuejian21.fragment.ClubFragment;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Clubbean;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Clubcoursebean;
import com.example.yuejian21.nongfusanquan.yuejian21.model.Clubmodel;
import com.example.yuejian21.nongfusanquan.yuejian21.model.Coursemodel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Nongfusanquan on 2017-10-19.
 */

public class ClubcourseActivity extends AppCompatActivity{

    private Button back_clubcourse;
    private RecyclerView recyclerView;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_clubcourse);
        recyclerView=(RecyclerView)findViewById(R.id.rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));//设置布局
        initView();
        initEvent();
        getData();
    }

    private void initView(){
        back_clubcourse =(Button)findViewById(R.id.back_clubcourse);

    }

    private void initEvent(){
        back_clubcourse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void getData() {
        Coursemodel Model=new Coursemodel();
        Call<List<Clubcoursebean>> call=Model.getclubcourse();
        call.enqueue(new Callback<List<Clubcoursebean>>() {
            @Override
            public void onResponse(Call<List<Clubcoursebean>> call, Response<List<Clubcoursebean>> response) {
                List<Clubcoursebean> data = response.body();  //获取数据
                recyclerView.setAdapter(new ClubcourseAdapter(ClubcourseActivity.this, data));
            }

            @Override
            public void onFailure(Call<List<Clubcoursebean>> call, Throwable t) {

            }
        });

    }
}
